package com.dianping.cat.home.service.transform;

import com.dianping.cat.home.service.entity.Domain;
import com.dianping.cat.home.service.entity.ServiceReport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.xml.sax.Attributes;



public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public Domain buildDomain(Attributes attributes) {
/* 17 */     String id = attributes.getValue("id");
/* 18 */     return new Domain(id);
  }




  public ServiceReport buildServiceReport(Attributes attributes) {
/* 25 */     String startTime = attributes.getValue("startTime");
/* 26 */     String domain = attributes.getValue("domain");
/* 27 */     String endTime = attributes.getValue("endTime");
/* 28 */     ServiceReport serviceReport = new ServiceReport(domain);

/* 30 */     if (startTime != null) {
/* 31 */       serviceReport.setStartTime(toDate(startTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/* 34 */     if (endTime != null) {
/* 35 */       serviceReport.setEndTime(toDate(endTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/* 38 */     return serviceReport;
  }


  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 43 */     if (value == null || value.length() == 0) {
/* 44 */       return defaultValue;
    }

/* 47 */     if (type == Boolean.class || type == boolean.class)
/* 48 */       return (T)Boolean.valueOf(value); 
/* 49 */     if (type == Integer.class || type == int.class)
/* 50 */       return (T)Integer.valueOf(value); 
/* 51 */     if (type == Long.class || type == long.class)
/* 52 */       return (T)Long.valueOf(value); 
/* 53 */     if (type == Short.class || type == short.class)
/* 54 */       return (T)Short.valueOf(value); 
/* 55 */     if (type == Float.class || type == float.class)
/* 56 */       return (T)Float.valueOf(value); 
/* 57 */     if (type == Double.class || type == double.class)
/* 58 */       return (T)Double.valueOf(value); 
/* 59 */     if (type == Byte.class || type == byte.class)
/* 60 */       return (T)Byte.valueOf(value); 
/* 61 */     if (type == Character.class || type == char.class) {
/* 62 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 64 */     return (T)value;
  }


  protected Date toDate(String str, String format, Date defaultValue) {
/* 69 */     if (str == null || str.length() == 0) {
/* 70 */       return defaultValue;
    }

    try {
/* 74 */       return (new SimpleDateFormat(format)).parse(str);
/* 75 */     } catch (ParseException e) {
/* 76 */       throw new RuntimeException(String.format("Unable to parse date(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/service/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */